package com.sc.nft.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.AddCatenaRequest;
import com.sc.nft.admin.request.CatenaListRequest;
import com.sc.nft.admin.request.UpdateCatenaRequest;
import com.sc.nft.admin.request.UserManageRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.CatenaInfo;
import com.sc.nft.entity.vo.CatenaVO;
import com.sc.nft.entity.vo.UserManageVO;
import com.sc.nft.service.CatenaInfoService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/catena")
@Api(tags="系列管理")
public class CatenaManageController {
    private final CatenaInfoService catenaInfoService;
    @PostMapping(value="/catenaList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "系列列表",notes="系列列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<CatenaVO> pageUserInfo(@Valid @RequestBody CatenaListRequest request){
        Page<CatenaInfo>page=catenaInfoService.catenaList(request.getPageNo(),request.getPageSize(),request.getName());
        return PageResult.success(page,CatenaVO.class);
    }

    @PostMapping(value="/addCatena", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增系列",notes="新增系列", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addCatena(@Valid @RequestBody AddCatenaRequest request){
        CatenaInfo catenaInfo=new CatenaInfo();
        catenaInfo.setName(request.getName());
        catenaInfo.setPresentation(request.getPresentation());
        catenaInfo.setType(request.getType());
        catenaInfo.setCreateId(request.getUserCreatorId());
        catenaInfo.insert();
        return Result.success();
    }

    @PostMapping(value="/updateCatena", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改系列",notes="修改系列", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateCatena(@Valid @RequestBody UpdateCatenaRequest request){
        CatenaInfo catenaInfo=new CatenaInfo();
        catenaInfo.setName(request.getName());
        catenaInfo.setPresentation(request.getPresentation());
        catenaInfo.setId(request.getId());
        catenaInfo.updateById();
        return Result.success();
    }

}
